﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Security;
using PdfSharp.Pdf.Advanced;

using CE.Mail;
using CE.Image;
using CE.Global;
using CE.Database;
using CE.User;
using CE.PostCode;
using CE.CarInsurance;
using CE.Provider;
using CE.Security;

/// <summary>
/// Summary description for BKICarInsurancePDFOutput
/// </summary>
///  
namespace CE.CarInsurance
{
    public class BKICarInsurancePDFOutput
    {
        private string _pageTitle;
        public string PageTitle
        {
            get { return _pageTitle; }
            set { _pageTitle = value; }
        }

        private string _proposalNo;
        public string ProposalNo
        {
            get { return _proposalNo; }
            set { _proposalNo = value; }
        }

        private string _revisionNo;
        public string RevisionNo
        {
            get { return _revisionNo; }
            set { _revisionNo = value; }
        }

        private string _quotationNo;
        public string QuotationNo
        {
            get { return _quotationNo; }
            set { _quotationNo = value; }
        }

        private string _producerCode;
        public string ProducerCode
        {
            get { return _producerCode; }
            set { _producerCode = value; }
        }

        private DateTime _Applicationdate;
        public DateTime ApplicationDate
        {
            get { return _Applicationdate; }
            set { _Applicationdate = value; }
        }


        #region Customer Profile
        private string _NRIC;
        public string NRIC
        {
            get { return _NRIC; }
            set { _NRIC = value; }
        }

        private string _customerName;
        public string CustomerName
        {
            get { return _customerName; }
            set { _customerName = value; }
        }

        string _customerAddress;
        public string CustomerAddress
        {
            get { return _customerAddress; }
            set { _customerAddress = value; }
        }

        string _customerUnitNo;
        public string CustomerUnitNo
        {
            get { return _customerUnitNo; }
            set { _customerUnitNo = value; }
        }

        string _customerHomeNo;
        public string CustomerHomeNo
        {
            get { return _customerHomeNo; }
            set { _customerHomeNo = value; }
        }

        string _customerPostCode;
        public string CustomerPostCode
        {
            get { return _customerPostCode; }
            set { _customerPostCode = value; }
        }

        string _officemobileNo;
        public string OfficeMobileNo
        {
            get { return _officemobileNo; }
            set { _officemobileNo = value; }
        }

        string _employersName;
        public string EmployersName
        {
            get { return _employersName; }
            set { _employersName = value; }
        }

        string _emailaddress;
        public string EmailAddress
        {
            get { return _emailaddress; }
            set { _emailaddress = value; }
        }

        string _customerGender;
        public string CustomerGender
        {
            get { return _customerGender; }
            set { _customerGender = value; }
        }

        DateTime _customerDOB;
        public DateTime CustomerDOB
        {
            get { return _customerDOB; }
            set { _customerDOB = value; }
        }

        string _customeroccupation;
        public string CustomerOccupation
        {
            get { return _customeroccupation; }
            set { _customeroccupation = value; }
        }

        string _customerjobnature;
        public string CustomerJobNature
        {
            get { return _customerjobnature; }
            set { _customerjobnature = value; }
        }

        string _customermaritalstatus;
        public string CustomerMaritalStatus
        {
            get { return _customermaritalstatus; }
            set { _customermaritalstatus = value; }
        }

        Int32 _customerdrivingexperience;
        public Int32 CustomerDrivingExperience
        {
            get { return _customerdrivingexperience; }
            set { _customerdrivingexperience = value; }
        }

        #endregion

        #region Addtnal Drivers

        string _driver1Name;
        public string Driver1Name
        {
            get { return _driver1Name; }
            set { _driver1Name = value; }
        }

        string _driver1Gender;
        public string Driver1gender
        {
            get { return _driver1Gender; }
            set { _driver1Gender = value; }
        }

        DateTime _driver1DOB;
        public DateTime Driver1DOB
        {
            get { return _driver1DOB; }
            set { _driver1DOB = value; }
        }

        string _driver1Occupation;
        public string Driver1Occupation
        {
            get { return _driver1Occupation; }
            set { _driver1Occupation = value; }
        }

        string _driver1JobNature;
        public string Driver1JobNature
        {
            get { return _driver1JobNature; }
            set { _driver1JobNature = value; }
        }

        string _driver1MaritalStatus;
        public string Driver1MaritalStatus
        {
            get { return _driver1MaritalStatus; }
            set { _driver1MaritalStatus = value; }
        }

        Int32 _driver1DrivingExperience;
        public Int32 Driver1DrivingExperience
        {
            get { return _driver1DrivingExperience; }
            set { _driver1DrivingExperience = value; }
        }

        string _driver2Name;
        public string Driver2Name
        {
            get { return _driver2Name; }
            set { _driver2Name = value; }
        }

        string _driver2Gender;
        public string Driver2gender
        {
            get { return _driver2Gender; }
            set { _driver2Gender = value; }
        }

        DateTime _driver2DOB;
        public DateTime Driver2DOB
        {
            get { return _driver2DOB; }
            set { _driver2DOB = value; }
        }

        string _driver2Occupation;
        public string Driver2Occupation
        {
            get { return _driver2Occupation; }
            set { _driver2Occupation = value; }
        }

        string _driver2JobNature;
        public string Driver2JobNature
        {
            get { return _driver2JobNature; }
            set { _driver2JobNature = value; }
        }

        string _driver2MaritalStatus;
        public string Driver2MaritalStatus
        {
            get { return _driver2MaritalStatus; }
            set { _driver2MaritalStatus = value; }
        }

        Int32 _driver2DrivingExperience;
        public Int32 Driver2DrivingExperience
        {
            get { return _driver2DrivingExperience; }
            set { _driver2DrivingExperience = value; }
        }

        string _driver3Name;
        public string Driver3Name
        {
            get { return _driver3Name; }
            set { _driver3Name = value; }
        }

        string _driver3Gender;
        public string Driver3gender
        {
            get { return _driver3Gender; }
            set { _driver3Gender = value; }
        }

        DateTime _driver3DOB;
        public DateTime Driver3DOB
        {
            get { return _driver3DOB; }
            set { _driver3DOB = value; }
        }

        string _driver3Occupation;
        public string Driver3Occupation
        {
            get { return _driver3Occupation; }
            set { _driver3Occupation = value; }
        }

        string _driver3JobNature;
        public string Driver3JobNature
        {
            get { return _driver3JobNature; }
            set { _driver3JobNature = value; }
        }

        string _driver3MaritalStatus;
        public string Driver3MaritalStatus
        {
            get { return _driver3MaritalStatus; }
            set { _driver3MaritalStatus = value; }
        }

        Int32 _driver3DrivingExperience;
        public Int32 Driver3DrivingExperience
        {
            get { return _driver3DrivingExperience; }
            set { _driver3DrivingExperience = value; }
        }


        string _driver4Name;
        public string Driver4Name
        {
            get { return _driver4Name; }
            set { _driver4Name = value; }
        }

        string _driver4Gender;
        public string Driver4gender
        {
            get { return _driver4Gender; }
            set { _driver4Gender = value; }
        }

        DateTime _driver4DOB;
        public DateTime Driver4DOB
        {
            get { return _driver4DOB; }
            set { _driver4DOB = value; }
        }

        string _driver4Occupation;
        public string Driver4Occupation
        {
            get { return _driver4Occupation; }
            set { _driver4Occupation = value; }
        }

        string _driver4JobNature;
        public string Driver4JobNature
        {
            get { return _driver4JobNature; }
            set { _driver4JobNature = value; }
        }

        string _driver4MaritalStatus;
        public string Driver4MaritalStatus
        {
            get { return _driver4MaritalStatus; }
            set { _driver4MaritalStatus = value; }
        }

        Int32 _driver4DrivingExperience;
        public Int32 Driver4DrivingExperience
        {
            get { return _driver4DrivingExperience; }
            set { _driver4DrivingExperience = value; }
        }

        string _driver5Name;
        public string Driver5Name
        {
            get { return _driver5Name; }
            set { _driver5Name = value; }
        }

        string _driver5Gender;
        public string Driver5gender
        {
            get { return _driver5Gender; }
            set { _driver5Gender = value; }
        }

        DateTime _driver5DOB;
        public DateTime Driver5DOB
        {
            get { return _driver5DOB; }
            set { _driver5DOB = value; }
        }

        string _driver5Occupation;
        public string Driver5Occupation
        {
            get { return _driver5Occupation; }
            set { _driver5Occupation = value; }
        }

        string _driver5JobNature;
        public string Driver5JobNature
        {
            get { return _driver5JobNature; }
            set { _driver5JobNature = value; }
        }

        string _driver5MaritalStatus;
        public string Driver5MaritalStatus
        {
            get { return _driver5MaritalStatus; }
            set { _driver5MaritalStatus = value; }
        }

        Int32 _driver5DrivingExperience;
        public Int32 Driver5DrivingExperience
        {
            get { return _driver5DrivingExperience; }
            set { _driver5DrivingExperience = value; }
        }



        #endregion

        #region Vehicle Details

        string _vehicleNo;
        public string VehicleNo
        {
            get { return _vehicleNo; }
            set { _vehicleNo = value; }
        }

        string _chassisNo;
        public string ChassisNo
        {
            get { return _chassisNo; }
            set { _chassisNo = value; }
        }

        string _bodyType;
        public string BodyType
        {
            get { return _bodyType; }
            set { _bodyType = value; }
        }

        string _engineNo;
        public string EngineNo
        {
            get { return _engineNo; }
            set { _engineNo = value; }
        }

        string _carMake;
        public string CarMake
        {
            get { return _carMake; }
            set { _carMake = value; }
        }

        string _carModel;
        public string CarModel
        {
            get { return _carModel; }
            set { _carModel = value; }
        }

        Int32 _yearOfManufacture;
        public Int32 YearOfManufacture
        {
            get { return _yearOfManufacture; }
            set { _yearOfManufacture = value; }
        }

        Int32 _yearOfRegistration;
        public Int32 YearOfRegistration
        {
            get { return _yearOfRegistration; }
            set { _yearOfRegistration = value; }
        }


        Int32 _carCC;
        public Int32 CarCC
        {
            get { return _carCC; }
            set { _carCC = value; }
        }

        Int32 _carSeaters;
        public Int32 CarSeaters
        {
            get { return _carSeaters; }
            set { _carSeaters = value; }
        }

        string _odometerReading;
        public string OdometerReading
        {
            get { return _odometerReading; }
            set { _odometerReading = value; }
        }

        string _estimatedMarketValue;
        public string EstimatedMarketValue
        {
            get { return _estimatedMarketValue; }
            set { _estimatedMarketValue = value; }
        }

        #endregion

        #region ClaimDetails

        string _currentInsuranceCo;
        public string CurrentInsuranceCo
        {
            get { return _currentInsuranceCo; }
            set { _currentInsuranceCo = value; }
        }

        string _policyNo;
        public string PolicyNo
        {
            get { return _policyNo; }
            set { _policyNo = value; }
        }

        DateTime _expiryCancellationDate;
        public DateTime ExpiryCancellationDate
        {
            get { return _expiryCancellationDate; }
            set { _expiryCancellationDate = value; }
        }

        string _last3yearsClaimXP;
        public string Last3YearsClaimXP
        {
            get { return _last3yearsClaimXP; }
            set { _last3yearsClaimXP = value; }
        }

        string _noClaimsLast3Years;
        public string NoClaimsLast3Years
        {
            get { return _noClaimsLast3Years; }
            set { _noClaimsLast3Years = value; }
        }

        string _NCDPercent;
        public string NCDPercent
        {
            get { return _NCDPercent; }
            set { _NCDPercent = value; }
        }

        string _OFD;
        public string OFD
        {
            get { return _OFD; }
            set { _OFD = value; }
        }

        //string _AddDiscount;
        //public string AdditionalDiscount
        //{
        //    get { return _AddDiscount; }
        //    set { _AddDiscount = value; }
        //}

        string _NCDProtector;
        public string NCDProtector
        {
            get { return _NCDProtector; }
            set { _NCDProtector = value; }
        }

        string _ncdNilDetails;
        public string NCDNilDetails
        {
            get { return _ncdNilDetails; }
            set { _ncdNilDetails = value; }
        }

        bool _isCarModified;
        public bool IsCarModified
        {
            get { return _isCarModified; }
            set { _isCarModified = value; }
        }

        string _modifiedReason;
        public string ModifiedReason
        {
            get { return _modifiedReason; }
            set { _modifiedReason = value; }
        }


        #endregion

        #region Policy Details

        string _financeCo;
        public string FinanceCo
        {
            get { return _financeCo; }
            set { _financeCo = value; }
        }

        string _usage;
        public string Usage
        {
            get { return _usage; }
            set { _usage = value; }
        }

        string _typeofcover;
        public string TypeOfCover
        {
            get { return _typeofcover; }
            set { _typeofcover = value; }
        }

        DateTime _periodFrom;
        public DateTime PeriodFrom
        {
            get { return _periodFrom; }
            set { _periodFrom = value; }
        }

        DateTime _periodTo;
        public DateTime PeriodTo
        {
            get { return _periodTo; }
            set { _periodTo = value; }
        }

        #endregion

        #region Other Info

        string _driveToWestMalaysia;
        public string DriveToWestMalaysia
        {
            get { return _driveToWestMalaysia; }
            set { _driveToWestMalaysia = value; }
        }

        bool _isConvictedOfMotoringOffense;
        public bool IsConvictedOfMotoringOffense
        {
            get { return _isConvictedOfMotoringOffense; }
            set { _isConvictedOfMotoringOffense = value; }
        }

        string _convictedReason;
        public string ConvictedReason
        {
            get { return _convictedReason; }
            set { _convictedReason = value; }
        }

        bool _isGivenDemeritPoints;
        public bool IsGivenDemeritPoints
        {
            get { return _isGivenDemeritPoints; }
            set { _isGivenDemeritPoints = value; }
        }

        string _demeritPointsReason;
        public string DemeritPointsReason
        {
            get { return _demeritPointsReason; }
            set { _demeritPointsReason = value; }
        }

        bool _isDisabled;
        public bool isDisabled
        {
            get { return _isDisabled; }
            set { _isDisabled = value; }
        }

        string _disablityReason;
        public string DisablityReason
        {
            get { return _disablityReason; }
            set { _disablityReason = value; }
        }

        bool _isRefusedMotorInsurance;
        public bool IsRefusedMotorInsurance
        {
            get { return _isRefusedMotorInsurance; }
            set { _isRefusedMotorInsurance = value; }
        }

        string _refusedReason;
        public string RefusedReason
        {
            get { return _refusedReason; }
            set { _refusedReason = value; }
        }

        bool _isTerminatedDueToPayment;
        public bool IsTerminatedDueToPayment
        {
            get { return _isTerminatedDueToPayment; }
            set { _isTerminatedDueToPayment = value; }
        }

        string _terminatedReason;
        public string TerminatedReason
        {
            get { return _terminatedReason; }
            set { _terminatedReason = value; }
        }



        #endregion

        #region Payment Details

        int _excess;
        public int Excess
        {
            get { return _excess; }
            set { _excess = value; }
        }

        float _totalPremium;
        public float TotalPremium
        {
            get { return _totalPremium; }
            set { _totalPremium = value; }
        }

        float _basicPremium;
        public float BasicPremium
        {
            get { return _basicPremium; }
            set { _basicPremium = value; }
        }

        float _ofdRate;
        public float OFDRate
        {
            get { return _ofdRate; }
            set { _ofdRate = value; }
        }

        //float _addDiscountRate;
        //public float AddDiscountRate
        //{
        //    get { return _addDiscountRate; }
        //    set { _addDiscountRate = value; }
        //}

        float _buyupdownRate;
        public float BuyUpDownRate
        {
            get { return _buyupdownRate; }
            set { _buyupdownRate = value; }
        }

        float _gstRate;
        public float GSTRate
        {
            get { return _gstRate; }
            set { _gstRate = value; }
        }

        float _ncdDiscountRate;
        public float NCDDiscountRate
        {
            get { return _ncdDiscountRate; }
            set { _ncdDiscountRate = value; }
        }

        float _ncdProtectorRate;
        public float NCDProtectorRate
        {
            get { return _ncdProtectorRate; }
            set { _ncdProtectorRate = value; }
        }

        float _grossPremium;
        public float GrossPremium
        {
            get { return _grossPremium; }
            set { _grossPremium = value; }
        }

        float _additionalDriverCharge;
        public float AdditionalDriverCharge
        {
            get { return _additionalDriverCharge; }
            set { _additionalDriverCharge = value; }
        }

        string _cardType;
        public string CardType
        {
            get { return _cardType; }
            set { _cardType = value; }
        }

        string _cardNo;
        public string CardNo
        {
            get { return _cardNo; }
            set { _cardNo = value; }
        }

        DateTime _cardExpiryDate;
        public DateTime CardExpiryDate
        {
            get { return _cardExpiryDate; }
            set { _cardExpiryDate = value; }
        }

        string _cardholdersName;
        public string CardholdersName
        {
            get { return _cardholdersName; }
            set { _cardholdersName = value; }
        }


        #endregion


        public BKICarInsurancePDFOutput()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private void DrawBoxWithText(XGraphics _objG, XColor _xcolor, int x, int y, int width, int height, double borderWidth, string strText, string strFontName, double fontSize, XFontStyle xFontStyle)
        {

            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = width;
            _rect.Height = height;
            XPen _pen = new XPen(_xcolor);
            _pen.Width = borderWidth;
            XFont font = new XFont(strFontName, fontSize, xFontStyle);
            _objG.DrawRectangle(_pen, _rect);
            _objG.DrawString(strText, font, XBrushes.Black, _rect, XStringFormats.Center);
        }

        private void DrawBoxWithTextList(XGraphics _objG, XColor _xcolor, int x, int y, int width, int height, int rows, int cols, double borderWidth, string strFontName, double fontSize, XFontStyle xFontStyle, string[,] _arrData, int[] _arrColsWidth)
        {

            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = width;
            _rect.Height = (height + 8) * rows;

            XColor _xOuterBoxColor = new XColor();
            _xOuterBoxColor.R = 0;
            _xOuterBoxColor.G = 0;
            _xOuterBoxColor.B = 0;

            XPen _pen = new XPen(_xcolor);
            _pen.Width = borderWidth;
            XFont font = new XFont(strFontName, fontSize, xFontStyle);
            XFont boldFont = new XFont(strFontName, fontSize, XFontStyle.Bold);
            _objG.DrawRectangle(_pen, _rect);

            System.Drawing.Rectangle _rectText = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rectText.X = x + 5;
            _rectText.Y = y + 5;
            _rectText.Width = width;
            _rectText.Height = height;

            for (int i = 0; i < rows; i++)
            {
                // Draw the text
                for (int j = 0; j < cols; j++)
                {
                    _rectText.Width = _arrColsWidth[j];
                    if (j == 0)
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), boldFont, XBrushes.Black, _rectText, XStringFormats.TopLeft);
                    }
                    else
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, _rectText, XStringFormats.TopLeft);
                    }
                    _rectText.X += _arrColsWidth[j];
                }
                _rectText.X = x + 5;
                _rectText.Y += height + 5;
            }

        }

        private void DrawTable(XGraphics _objG, int x, int y, int rows, int cols, int rowHeight, int[] _arrColsWidth, string[] _arrHeader, string[,] _arrData)
        {
            XColor _xcolor = new XColor();
            _xcolor.R = 0;
            _xcolor.G = 0;
            _xcolor.B = 0;
            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
            _rect.X = x;
            _rect.Y = y;
            _rect.Width = _arrColsWidth[0];
            _rect.Height = rowHeight;
            XPen _pen = new XPen(_xcolor);
            _pen.Width = 0.5d;
            XFont font = new XFont("Verdana", 5, XFontStyle.Regular);

            for (int h = 0; h < cols; h++)
            {
                _rect.Width = _arrColsWidth[h];
                _objG.DrawRectangle(_pen, _rect);
                _objG.DrawString(_arrHeader[h].ToString(), font, XBrushes.Black,
          new XRect(_rect.X + 3, _rect.Y + 3, 10, 10),
          XStringFormats.TopLeft);
                _rect.X += _arrColsWidth[h];
            }

            _rect.Y += rowHeight;
            _rect.X = x;

            for (int i = 0; i < rows; i++)
            {
                // Draw the text
                for (int j = 0; j < cols; j++)
                {
                    _rect.Width = _arrColsWidth[j];

                    _objG.DrawRectangle(_pen, _rect);
                    _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black,
              new XRect(_rect.X + 3, _rect.Y + 3, 10, 10),
              XStringFormats.TopLeft);
                    _rect.X += _arrColsWidth[j];
                }
                _rect.Y += rowHeight;
                _rect.X = x;
            }
        }

        public string BKIPDFProposalForm(string strfilename,int userType)
        {   //userType
            // 1 = Provider
            // 0 = Client/Applicant
            string inputfile = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.FileOutputPath").ToString();
            inputfile += "pdfoutput\\BKI\\BKI.pdf";
            

            // Open the input files
            PdfDocument inputDocument = PdfReader.Open(inputfile, PdfDocumentOpenMode.Import);

            PdfDocument outputDocument = new PdfDocument();
            PdfSecuritySettings securitySettings = outputDocument.SecuritySettings;
            // Setting one of the passwords automatically sets the security level to 
            // PdfDocumentSecurityLevel.Encrypted128Bit.
            //securitySettings.UserPassword = "user";
            //securitySettings.OwnerPassword = "owner";

            //securitySettings.PermitAccessibilityExtractContent = false;
            //securitySettings.PermitAnnotations = false;
            //securitySettings.PermitAssembleDocument = false;
            //securitySettings.PermitExtractContent = false;
            //securitySettings.PermitFormsFill = true;
            //securitySettings.PermitFullQualityPrint = false;
            //securitySettings.PermitModifyDocument = false;
            //securitySettings.PermitPrint = false;

            outputDocument.Info.Title = _pageTitle;

            // Show consecutive pages facing. Requires Acrobat 5 or higher.
            //outputDocument.PageLayout = PdfPageLayout.TwoColumnLeft;
            outputDocument.PageLayout = PdfPageLayout.SinglePage;
            String str = string.Empty;
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            // Create a font
            XFont font = new XFont("Tahoma", 8, XFontStyle.Regular, options);
            XFont fontNormal = new XFont("Tahoma", 7.5, XFontStyle.Regular, options);
            XFont fontMedium = new XFont("Tahoma", 7, XFontStyle.Regular, options);
            XFont fontSmall = new XFont("Tahoma", 6, XFontStyle.Regular, options);
            XFont fontBold = new XFont("Tahoma", 8, XFontStyle.Bold, options);
            XFont fontMediumBold = new XFont("Tahoma", 7, XFontStyle.Bold, options);
            XFont fontSmallBold = new XFont("Tahoma", 6, XFontStyle.Bold, options);
            //XStringFormat format = new XStringFormat();
            //format.Alignment = XStringAlignment.Center;
            //format.LineAlignment = XLineAlignment.Far;
                      
            int curX = 30;
            int curY = 30;
            
            PdfPage outputpage = outputDocument.AddPage(inputDocument.Pages[0]);

            XGraphics gfx = XGraphics.FromPdfPage(outputpage);

            str = DateTime.Now.ToString();
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 320, curY + 80, 100, 20), XStringFormat.TopLeft);
            str = "123"; //_pageTitle;
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 500, curY + 80, 100, 20), XStringFormat.TopLeft);


            str = "โสภณ วรสิทธิ์ชัย";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 100, curY + 160, 100, 20), XStringFormat.TopLeft);
            str = "Engineer";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 400, curY + 160, 100, 20), XStringFormat.TopLeft);
            
            str = "413 address";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 100, curY + 180, 100, 20), XStringFormat.TopLeft);
            str = "moo";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 300, curY + 180, 100, 20), XStringFormat.TopLeft);
            str = "soi";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 400, curY + 180, 100, 20), XStringFormat.TopLeft);
            
            str = "ถนน";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 100, curY + 200, 100, 20), XStringFormat.TopLeft);
            str = "ตำบล";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 300, curY + 200, 100, 20), XStringFormat.TopLeft);
            str = "อำเภอ";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 450, curY + 200, 100, 20), XStringFormat.TopLeft);

            str = "จังหวัด";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 100, curY + 230, 100, 20), XStringFormat.TopLeft);
            str = "รหัสไปรษณีย์";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 300, curY + 230, 100, 20), XStringFormat.TopLeft);
            str = "โทรศัพท์";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 450, curY + 230, 100, 20), XStringFormat.TopLeft);

            str = "รหัสรถ";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 20, curY + 300, 100, 20), XStringFormat.TopLeft);
            str = "ยี่ห้อ";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 80, curY + 300, 100, 20), XStringFormat.TopLeft);
            str = "เลขทะเบียน";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 180, curY + 300, 100, 20), XStringFormat.TopLeft);
            str = "Chassis";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 250, curY + 300, 100, 20), XStringFormat.TopLeft);
            str = "Year";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 400, curY + 300, 100, 20), XStringFormat.TopLeft);
            str = "cc";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 450, curY + 300, 100, 20), XStringFormat.TopLeft);
            
            str = "Start Policy";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 180, curY + 380, 100, 20), XStringFormat.TopLeft);
            str = "End Date";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 340, curY + 380, 100, 20), XStringFormat.TopLeft);
            
            str = "Name Surname";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 300, curY + 440, 100, 20), XStringFormat.TopLeft);
            
            str = "DOB Date";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 260, curY + 460, 100, 20), XStringFormat.TopLeft);
            str = "Driver License";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 380, curY + 460, 100, 20), XStringFormat.TopLeft);

            str = "SumInsured 100";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 120, curY + 560, 100, 20), XStringFormat.TopLeft);
            str = "Net vol 100";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 120, curY + 580, 100, 20), XStringFormat.TopLeft);
            str = "Total vol 100";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 120, curY + 600, 100, 20), XStringFormat.TopLeft);
            str = "CTPL 100";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 120, curY + 630, 100, 20), XStringFormat.TopLeft);
            str = "Vol + CTPL 100";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 120, curY + 650, 100, 20), XStringFormat.TopLeft);
            str = "NCB 100";
            gfx.DrawString(str, font, XBrushes.DarkBlue, new XRect(curX + 120, curY + 670, 100, 20), XStringFormat.TopLeft);


            // Save the document...
            //string filename = "CompareDocument1.pdf";
            string _filePath = GetFilePathBKI();
            string filename = _filePath + strfilename + ".pdf";

            outputDocument.Save(filename);
            // ...and start a viewer.
            //Process.Start(filename);
            return filename;
        }

        public string BKIPDFProposalFormbak(string strfilename, int userType)
        {
            //userType
            // 1 = Provider
            // 0 = Client/Applicant

            // Create a new PDF document
            PdfDocument document = new PdfDocument();
            document.Info.Title = _pageTitle;

            // Create an empty page
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);
            //XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            // Create a font
            XFont font = new XFont("Verdana", 8, XFontStyle.Bold);
            XFont fontNormal = new XFont("Verdana", 8, XFontStyle.Regular);
            XFont fontSmall = new XFont("Verdana", 6, XFontStyle.Regular);
            XFont fontBold = new XFont("Verdana", 8, XFontStyle.Bold);
            XFont fontBig = new XFont("Verdana", 10, XFontStyle.Bold);
            XColor _xcolor = new XColor();
            _xcolor.R = 0;
            _xcolor.G = 0;
            _xcolor.B = 0;
            
            System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(20, 10, 500, 100);
            XPen _pen = new XPen(_xcolor);

            int curX = 50;
            int curY = 30;

            if (userType == 1)
            {
                gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "images\\pdf\\libertyheader.jpg"), new XRect(curX, curY, 520, 61));
                curY += 65;

            }
            else
            {
                gfx.DrawString("Liberty Insurance Pte Ltd", fontBig, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
                curY += 45;
            }

            

            gfx.DrawString("MOTOR INSURANCE PROPOSAL", fontBold, XBrushes.Black, new XRect(curX, curY, 520, 20), XStringFormat.TopCenter);
            curY += 10;

            curY += 15;

            gfx.DrawString("Proposal No", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_proposalNo, fontNormal, XBrushes.Black, new XRect(curX + 80, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Revision No", fontBold, XBrushes.Black, new XRect(curX + 180, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_revisionNo, fontNormal, XBrushes.Black, new XRect(curX + 250, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Quotation No", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_quotationNo, fontNormal, XBrushes.Black, new XRect(curX + 420, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Producer Code", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            //gfx.DrawString(_producerCode, fontNormal, XBrushes.Black, new XRect(curX + 80, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("D9999-CX", fontNormal, XBrushes.Black, new XRect(curX + 80, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Date", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 180, 20), XStringFormat.TopLeft);
            gfx.DrawString(DateTime.Now.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 420, curY, 100, 20), XStringFormat.TopLeft);

            curY += 16;
            gfx.DrawString("Insured's Particulars", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 11;
            gfx.DrawString("IC/ROC Number:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_NRIC, fontNormal, XBrushes.Black, new XRect(curX + 80, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Name", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_customerName, fontNormal, XBrushes.Black, new XRect(curX + 420, curY, 150, 20), XStringFormat.TopLeft);

            curY += 11;
            gfx.DrawString("Address:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 60), XStringFormat.TopLeft);
            gfx.DrawString("#" + _customerUnitNo + "-" + _customerHomeNo, fontNormal, XBrushes.Black, new XRect(curX + 80, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Mobile No/Office No:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_officemobileNo, fontNormal, XBrushes.Black, new XRect(curX + 420, curY, 150, 20), XStringFormat.TopLeft);
            curY += 11;
            gfx.DrawString(_customerAddress, fontNormal, XBrushes.Black, new XRect(curX + 80, curY, 100, 20), XStringFormat.TopLeft);

            curY += 22;
            gfx.DrawString("Employer's Name & Trade:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_employersName, fontNormal, XBrushes.Black, new XRect(curX + 130, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Email Address", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);           
            gfx.DrawString(_emailaddress, fontNormal, XBrushes.Black, new XRect(curX + 420, curY, 150, 20), XStringFormat.TopLeft);

            //gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);
            curY += 20;
            gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);
            gfx.DrawString("Name", fontBold, XBrushes.Black, new XRect(curX + 42, curY + 3, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Sex", fontBold, XBrushes.Black, new XRect(curX + 125, curY + 3, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Date of Birth", fontBold, XBrushes.Black, new XRect(curX + 153, curY + 3, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString("Occupation", fontBold, XBrushes.Black, new XRect(curX + 220, curY + 3, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString("Indoor/Outdoor", fontBold, XBrushes.Black, new XRect(curX + 295, curY + 3, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString("Marital Status", fontBold, XBrushes.Black, new XRect(curX + 375, curY + 3, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString("Driving XP(Yrs)", fontBold, XBrushes.Black, new XRect(curX + 442, curY + 3, 150, 20), XStringFormat.TopLeft);

            curY += 15;
            gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);
            gfx.DrawString(_customerName, fontNormal, XBrushes.Black, new XRect(curX + 4, curY + 3, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_customerGender, fontNormal, XBrushes.Black, new XRect(curX + 122, curY + 3, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_customerDOB.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 158, curY + 3, 100, 20), XStringFormat.TopLeft);

            bool isOccupationlong = false;
            string occ1 = "";
            string occ2 = "";
            if (_customeroccupation.Length > 18)
            {
                isOccupationlong = true;
                
                occ1 = _customeroccupation.Substring(0, 17);
                occ2 = _customeroccupation.Substring(17);
                gfx.DrawString(occ1, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
            }
            else
            {
                gfx.DrawString(_customeroccupation, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
            }
            gfx.DrawString(_customerjobnature, fontNormal, XBrushes.Black, new XRect(curX + 305, curY + 3, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_customermaritalstatus, fontNormal, XBrushes.Black, new XRect(curX + 385, curY + 3, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_customerdrivingexperience.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 475, curY + 3, 100, 20), XStringFormat.TopLeft);
           
            if (isOccupationlong)
            {
                curY += 15;
                gfx.DrawString(occ2, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);

            }
            curY += 15;
            gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);
          
             //e.Graphics.PageUnit=GraphicsUnit.Pixel
             //e.Graphics.DrawLine(p,10,10,300,10)

            bool isOccupationlongDriver1 = false;
            string occ1Driver1 = "";
            string occ2Driver1 = "";

            if (_driver1Name != "")
            {
                gfx.DrawString(_driver1Name, fontNormal, XBrushes.Black, new XRect(curX + 4, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver1Gender, fontNormal, XBrushes.Black, new XRect(curX + 122, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver1DOB.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 158, curY + 3, 100, 20), XStringFormat.TopLeft);

                if (_driver1Occupation.Length > 18)
                {
                    isOccupationlongDriver1 = true;

                    occ1Driver1 = _driver1Occupation.Substring(0, 17);
                    occ2Driver1 = _driver1Occupation.Substring(17);
                    gfx.DrawString(occ1Driver1, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
                else
                {
                    gfx.DrawString(_driver1Occupation, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }

                gfx.DrawString(_driver1JobNature, fontNormal, XBrushes.Black, new XRect(curX + 305, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver1MaritalStatus, fontNormal, XBrushes.Black, new XRect(curX + 385, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver1DrivingExperience.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 475, curY + 3, 100, 20), XStringFormat.TopLeft);
                              
                if (isOccupationlongDriver1)
                {
                    curY += 15;
                    gfx.DrawString(occ2Driver1, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
            }                   
            curY += 15;
            gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);


            bool isOccupationlongDriver2 = false;
            string occ1Driver2 = "";
            string occ2Driver2 = "";

            if (_driver2Name != "")
            {
                gfx.DrawString(_driver2Name, fontNormal, XBrushes.Black, new XRect(curX + 4, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver2Gender, fontNormal, XBrushes.Black, new XRect(curX + 122, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver2DOB.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 158, curY + 3, 100, 20), XStringFormat.TopLeft);

                if (_driver2Occupation.Length > 18)
                {
                    isOccupationlongDriver2 = true;

                    occ1Driver2 = _driver2Occupation.Substring(0, 17);
                    occ2Driver2 = _driver2Occupation.Substring(17);
                    gfx.DrawString(occ1Driver2, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
                else
                {
                    gfx.DrawString(_driver2Occupation, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }

                gfx.DrawString(_driver2JobNature, fontNormal, XBrushes.Black, new XRect(curX + 305, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver2MaritalStatus, fontNormal, XBrushes.Black, new XRect(curX + 385, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver2DrivingExperience.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 475, curY + 3, 100, 20), XStringFormat.TopLeft);
                
                if (isOccupationlongDriver2)
                {
                    curY += 15;
                    gfx.DrawString(occ2Driver2, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
            }

            curY += 15;
            gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);

            bool isOccupationlongDriver3 = false;
            string occ1Driver3 = "";
            string occ2Driver3 = "";

            if (_driver3Name != "")
            {
                gfx.DrawString(_driver3Name, fontNormal, XBrushes.Black, new XRect(curX + 4, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver3Gender, fontNormal, XBrushes.Black, new XRect(curX + 122, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver3DOB.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 158, curY + 3, 100, 20), XStringFormat.TopLeft);
                if (_driver3Occupation.Length > 18)
                {
                    isOccupationlongDriver3 = true;

                    occ1Driver3 = _driver3Occupation.Substring(0, 17);
                    occ2Driver3 = _driver3Occupation.Substring(17);
                    gfx.DrawString(occ1Driver3, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
                else
                {
                    gfx.DrawString(_driver3Occupation, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }

                gfx.DrawString(_driver3JobNature, fontNormal, XBrushes.Black, new XRect(curX + 305, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver3MaritalStatus, fontNormal, XBrushes.Black, new XRect(curX + 385, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver3DrivingExperience.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 475, curY + 3, 100, 20), XStringFormat.TopLeft);

                if (isOccupationlongDriver3)
                {
                    curY += 15;
                    gfx.DrawString(occ2Driver3, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }

                curY += 15;
                gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);
            }

            bool isOccupationlongDriver4 = false;
            string occ1Driver4 = "";
            string occ2Driver4 = "";

            if (_driver4Name != "")
            {
                gfx.DrawString(_driver4Name, fontNormal, XBrushes.Black, new XRect(curX + 4, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver4Gender, fontNormal, XBrushes.Black, new XRect(curX + 122, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver4DOB.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 158, curY + 3, 100, 20), XStringFormat.TopLeft);
                if (_driver4Occupation.Length > 18)
                {
                    isOccupationlongDriver4 = true;

                    occ1Driver4 = _driver4Occupation.Substring(0, 17);
                    occ2Driver4 = _driver4Occupation.Substring(17);
                    gfx.DrawString(occ1Driver4, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
                else
                {
                    gfx.DrawString(_driver4Occupation, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
               
                gfx.DrawString(_driver4JobNature, fontNormal, XBrushes.Black, new XRect(curX + 305, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver4MaritalStatus, fontNormal, XBrushes.Black, new XRect(curX + 385, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver4DrivingExperience.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 475, curY + 3, 100, 20), XStringFormat.TopLeft);

                if (isOccupationlongDriver4)
                {
                    curY += 15;
                    gfx.DrawString(occ2Driver4, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }

                curY += 15;
                gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);
              
            }

            bool isOccupationlongDriver5 = false;
            string occ1Driver5 = "";
            string occ2Driver5 = "";

            if (_driver5Name != "")
            {
                gfx.DrawString(_driver5Name, fontNormal, XBrushes.Black, new XRect(curX + 4, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver5Gender, fontNormal, XBrushes.Black, new XRect(curX + 122, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver5DOB.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 158, curY + 3, 100, 20), XStringFormat.TopLeft);
                if (_driver5Occupation.Length > 18)
                {
                    isOccupationlongDriver5 = true;

                    occ1Driver5 = _driver5Occupation.Substring(0, 17);
                    occ2Driver5 = _driver5Occupation.Substring(17);
                    gfx.DrawString(occ1Driver5, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }
                else
                {
                    gfx.DrawString(_driver5Occupation, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }

                gfx.DrawString(_driver5JobNature, fontNormal, XBrushes.Black, new XRect(curX + 305, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver5MaritalStatus, fontNormal, XBrushes.Black, new XRect(curX + 385, curY + 3, 100, 20), XStringFormat.TopLeft);
                gfx.DrawString(_driver5DrivingExperience.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 475, curY + 3, 100, 20), XStringFormat.TopLeft);

                if (isOccupationlongDriver5)
                {
                    curY += 15;
                    gfx.DrawString(occ2Driver5, fontNormal, XBrushes.Black, new XRect(curX + 212, curY + 3, 100, 20), XStringFormat.TopLeft);
                }

                curY += 15;
                gfx.DrawLine(new XPen(_xcolor), curX, curY, 565, curY);

            }


            if (_driver5Name != "")
            {
                int linecol = 105;

                if (isOccupationlong)
                    linecol += 15;

                if (isOccupationlongDriver1)
                    linecol += 15;

                if (isOccupationlongDriver2)
                    linecol += 15;

                if (isOccupationlongDriver3)
                    linecol += 15;

                if (isOccupationlongDriver4)
                    linecol += 15;

                if (isOccupationlongDriver5)
                    linecol += 15;

                gfx.DrawLine(new XPen(_xcolor), curX, curY, curX, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 120, curY, curX + 120, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 153, curY, curX + 153, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 211, curY, curX + 211, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 295, curY, curX + 295, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 370, curY, curX + 370, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 440, curY, curX + 440, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 515, curY, curX + 515, curY - linecol);
            }
            else if (_driver4Name != "")
            {

                int linecol = 90;

                if (isOccupationlong)
                    linecol += 15;

                if (isOccupationlongDriver1)
                    linecol += 15;

                if (isOccupationlongDriver2)
                    linecol += 15;

                if (isOccupationlongDriver3)
                    linecol += 15;

                if (isOccupationlongDriver4)
                    linecol += 15;

                if (isOccupationlongDriver5)
                    linecol += 15;

                gfx.DrawLine(new XPen(_xcolor), curX, curY, curX, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 120, curY, curX + 120, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 153, curY, curX + 153, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 211, curY, curX + 211, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 295, curY, curX + 295, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 370, curY, curX + 370, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 440, curY, curX + 440, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 515, curY, curX + 515, curY - linecol);
            }
            else if (_driver3Name != "")
            {
                int linecol = 75;

                if (isOccupationlong)
                    linecol += 15;

                if (isOccupationlongDriver1)
                    linecol += 15;

                if (isOccupationlongDriver2)
                    linecol += 15;

                if (isOccupationlongDriver3)
                    linecol += 15;

                if (isOccupationlongDriver4)
                    linecol += 15;

                if (isOccupationlongDriver5)
                    linecol += 15;

                gfx.DrawLine(new XPen(_xcolor), curX, curY, curX, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 120, curY, curX + 120, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 153, curY, curX + 153, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 211, curY, curX + 211, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 295, curY, curX + 295, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 370, curY, curX + 370, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 440, curY, curX + 440, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 515, curY, curX + 515, curY - linecol);
            }
            else
            {
                int linecol = 60;

                if (isOccupationlong)
                    linecol += 15;

                if (isOccupationlongDriver1)
                    linecol += 15;

                if (isOccupationlongDriver2)
                    linecol += 15;

                if (isOccupationlongDriver3)
                    linecol += 15;

                if (isOccupationlongDriver4)
                    linecol += 15;

                if (isOccupationlongDriver5)
                    linecol += 15;

                gfx.DrawLine(new XPen(_xcolor), curX, curY, curX, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 120, curY, curX + 120, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 153, curY, curX + 153, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 211, curY, curX + 211, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 295, curY, curX + 295, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 370, curY, curX + 370, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 440, curY, curX + 440, curY - linecol);
                gfx.DrawLine(new XPen(_xcolor), curX + 515, curY, curX + 515, curY - linecol);
            }

           
            curY += 20;
            gfx.DrawString("Vehicle Details", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Vehicle Number:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_vehicleNo.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Chassis Number:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_chassisNo.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Body Type", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_bodyType, fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Engine No:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_engineNo.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Make:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_carMake, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Year of Manufacture", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_yearOfManufacture.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Model:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_carModel, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Year of Registration ", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_yearOfRegistration.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Engine CC/Ton:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_carCC.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Seaters:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_carSeaters.ToString(), fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Odometer Reading:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_odometerReading, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Estimated Mkt Value:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_estimatedMarketValue, fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 20;
            gfx.DrawString("Claim Details", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx.DrawString("Current Insurance Co:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_currentInsuranceCo, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Vehicle No:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_vehicleNo.ToUpper(), fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx.DrawString("Policy No:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawLine(new XPen(_xcolor), curX + 50, curY + 10, curX + 150, curY + 10);
            gfx.DrawString(_policyNo, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("Expiry/Cancellation Date:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);

            string expiryDate;
            if (_expiryCancellationDate.ToString("dd-MM-yyyy") == "01-01-1990")
            {
                expiryDate = "";
            }
            else
            {
                expiryDate = _expiryCancellationDate.ToString("dd-MM-yyyy");
            }

            gfx.DrawString(expiryDate, fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("Last 3 Years Claim XP", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_last3yearsClaimXP, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("No Claims In Last 3 Years:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_noClaimsLast3Years, fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawString("NCD%:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_NCDPercent, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString("OFD:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx.DrawString(_OFD, fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx.DrawString("NCD Protector:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawString(_NCDProtector, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);

            curY += 20;
            gfx.DrawString("If NCD is Nil, Please Provide Details:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx.DrawRectangle(new XPen(_xcolor), curX, curY, 8, 8);
            gfx.DrawString("First time buying a vehicle", fontNormal, XBrushes.Black, new XRect(curX + 30, curY, 100, 20), XStringFormat.TopLeft);

            bool isOtherReason = true;

            if (_ncdNilDetails.ToLower() == "first time buying a vehicle")
            {
                isOtherReason = false;
                gfx.DrawLine(new XPen(_xcolor), curX, curY, curX + 8, curY + 8);
                gfx.DrawLine(new XPen(_xcolor), curX + 8, curY, curX, curY + 8);
            }

            gfx.DrawRectangle(new XPen(_xcolor), curX + 200, curY, 8, 8);
            gfx.DrawString("2nd or 3rd vehicle", fontNormal, XBrushes.Black, new XRect(curX + 230, curY, 100, 20), XStringFormat.TopLeft);
            if (_ncdNilDetails.ToLower() == "2nd or 3rd vehicle")
            {
                isOtherReason = false;
                gfx.DrawLine(new XPen(_xcolor), curX + 200, curY, curX + 208, curY + 8);
                gfx.DrawLine(new XPen(_xcolor), curX + 208, curY, curX + 200, curY + 8);
            }


            curY += 12;
            gfx.DrawRectangle(new XPen(_xcolor), curX, curY, 8, 8);
            gfx.DrawString("Have been driving other's vehicle", fontNormal, XBrushes.Black, new XRect(curX + 30, curY, 100, 20), XStringFormat.TopLeft);
            if (_ncdNilDetails.ToLower() == "have been driving others' car")
            {
                isOtherReason = false;
                gfx.DrawLine(new XPen(_xcolor), curX, curY, curX + 8, curY + 8);
                gfx.DrawLine(new XPen(_xcolor), curX + 8, curY, curX, curY + 8);
            }


            gfx.DrawRectangle(new XPen(_xcolor), curX + 200, curY, 8, 8);
            gfx.DrawString("Other reason,please specify", fontNormal, XBrushes.Black, new XRect(curX + 230, curY, 100, 20), XStringFormat.TopLeft);

            if (isOtherReason)
            {
                if (_ncdNilDetails != "" || _ncdNilDetails == "-1")
                {
                    string ncdreason = "Not Applicable";
                    if (_ncdNilDetails == "Others")
                    {
                        ncdreason = _ncdNilDetails;
                    }

                    gfx.DrawString(ncdreason, fontNormal, XBrushes.Black, new XRect(curX + 350, curY, 100, 20), XStringFormat.TopLeft);
                    gfx.DrawLine(new XPen(_xcolor), curX + 200, curY, curX + 208, curY + 8);
                    gfx.DrawLine(new XPen(_xcolor), curX + 208, curY, curX + 200, curY + 8);
                }
            }

            gfx.DrawLine(new XPen(_xcolor), curX + 350, curY + 10, curX + 480, curY + 10);

            curY += 14;
            gfx.DrawString("Has the vehicle been modified/converted in anyway from the maker's specifications?", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx.DrawRectangle(new XPen(_xcolor), curX, curY, 8, 8);
            gfx.DrawString("Yes", fontNormal, XBrushes.Black, new XRect(curX + 30, curY, 100, 20), XStringFormat.TopLeft);
            if (IsCarModified)
            {

                gfx.DrawLine(new XPen(_xcolor), curX, curY, curX + 8, curY + 8);
                gfx.DrawLine(new XPen(_xcolor), curX + 8, curY, curX, curY + 8);
            }

            gfx.DrawRectangle(new XPen(_xcolor), curX + 200, curY, 8, 8);
            gfx.DrawString("No", fontNormal, XBrushes.Black, new XRect(curX + 230, curY, 100, 20), XStringFormat.TopLeft);
            if (!IsCarModified)
            {

                gfx.DrawLine(new XPen(_xcolor), curX + 200, curY, curX + 208, curY + 8);
                gfx.DrawLine(new XPen(_xcolor), curX + 208, curY, curX + 200, curY + 8);
            }

            gfx.DrawString("If yes please specify", fontNormal, XBrushes.Black, new XRect(curX + 250, curY, 100, 20), XStringFormat.TopLeft);
            gfx.DrawLine(new XPen(_xcolor), curX + 350, curY + 10, curX + 480, curY + 10);
            if (IsCarModified)
            {
                gfx.DrawString(_modifiedReason, fontNormal, XBrushes.Black, new XRect(curX + 350, curY, 100, 20), XStringFormat.TopLeft);
           }

            if (_driver5Name != "")
            {
                curY += 185;
            }
            else if (_driver4Name != "")
            {
                curY += 200;
            }
            else if (_driver3Name != "")
            {
                curY += 215;
            }
            else
            {
                curY += 230;
            }

            if (isOccupationlong)
                curY -= 15;

            if (isOccupationlongDriver1)
                curY -= 15;

            if (isOccupationlongDriver2)
                curY -= 15;

            if (isOccupationlongDriver3)
                curY -= 15;

            if (isOccupationlongDriver4)
                curY -= 15;

            if (isOccupationlongDriver5)
                curY -= 15;
           
            gfx.DrawString("Page 1 of 2", fontSmall, XBrushes.Black, new XRect(curX + 450, curY, 200, 20), XStringFormat.TopLeft);

            //Page 2
            // Create an empty page
            PdfPage page2 = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx2 = XGraphics.FromPdfPage(page2);

            curX = 50;
            curY = 30;

            gfx2.DrawString("Policy Details", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Finance Company:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_financeCo, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("Usage:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("Private Use", fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("Type of Cover:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);

            string _planname1 = "Comprehensive";
            string _planname2 = "";
            if (_typeofcover.Trim() == "Comprehensive - Preferred")
            {
                _planname2 = "Pte Car-Preferred Plan";
            }
            else
            {
                _planname2 = "Pte Car-Standard Plan";
            }

            gfx2.DrawString(_planname1, fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString(_planname2, fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Period From:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_periodFrom.ToString("dd-MM-yyyy") + " 00:00", fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("Period To:", fontBold, XBrushes.Black, new XRect(curX + 320, curY, 150, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_periodTo.ToString("dd-MM-yyyy") + " 23:59", fontNormal, XBrushes.Black, new XRect(curX + 440, curY, 150, 20), XStringFormat.TopLeft);

            curY += 16;
            gfx2.DrawString("Other Information", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("How often do you drive to West Malaysia?", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_driveToWestMalaysia, fontNormal, XBrushes.Black, new XRect(curX + 450, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("Have you or any driver named under Section V", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("1)Been convicted of any motoring offences(other than parking) in the last three years or have ", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(isTrue(_isConvictedOfMotoringOffense.ToString()), fontNormal, XBrushes.Black, new XRect(curX + 450, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("prosecutions pending?", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("2)Been given demerit points? If Yes, please state name of driver,total no of demerit points accumulated", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(isTrue(_isGivenDemeritPoints.ToString()), fontNormal, XBrushes.Black, new XRect(curX + 450, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("during the last 24 mths,the date and type of offence.", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("3)Suffer from defective vision or hearing, heart condition, epilepsy, diabetes or any physical or mental", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(isTrue(_isDisabled.ToString()), fontNormal, XBrushes.Black, new XRect(curX + 450, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("disability or infirmity?", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("4)Been refused motor insurance at any time or subjected to special conditions?", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(isTrue(_isRefusedMotorInsurance.ToString()), fontNormal, XBrushes.Black, new XRect(curX + 450, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("5) Do you have any insurance terminated in the last 12 months due to a breach of any premium payment", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(isTrue(_isTerminatedDueToPayment.ToString()), fontNormal, XBrushes.Black, new XRect(curX + 450, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("condition?", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("If any of the above answers are 'Yes' please provide details below", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawLine(new XPen(_xcolor), curX, curY + 12, curX + 270, curY + 12);
            string OtherInfoReasons = "";
            if (_convictedReason != "")
            {
                OtherInfoReasons = _convictedReason;
            }
            if (_demeritPointsReason != "")
            {
                OtherInfoReasons = OtherInfoReasons + "," + _demeritPointsReason;
            }
            if (_disablityReason != "")
            {
                OtherInfoReasons = OtherInfoReasons + "," + _disablityReason;
            }

            if (_refusedReason != "")
            {
                OtherInfoReasons = OtherInfoReasons + "," + _refusedReason;
            }

            if (_terminatedReason != "")
            {
                OtherInfoReasons = OtherInfoReasons + "," + _terminatedReason;
            }


            gfx2.DrawString(OtherInfoReasons, fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 25;
            gfx2.DrawString("Excess", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("1) $" + _excess.ToString() + " applicable to Insured and up to 2 named drivers", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("2) $500 additional excess applicable to unnamed drivers", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("3)	$3,000 additional excess applicable to drivers (named or unnamed) who are below 24 or above 70 or with less than", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString(" 12 months’ driving experience. This additional excess shall not apply to the Insured.", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("4)	$100 windscreen excess. Windscreen cover will be automatically reinstated free of charge.", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 25;
            gfx2.DrawString("Payment Before Cover Warranty (Private Vehicles)", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Please note that the total premium must be paid and actually received in full by the Company (or the intermediary through whom this "
            + " policy was affected) on or ", fontSmall, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("before the inception date of coverage, failing which the policy shall be deemed to be automatically cancelled and no benefits whatsoever shall be payable by the ", fontSmall, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("Company", fontSmall, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

            curY += 15;
            gfx2.DrawString("Premium Details", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("Quotation Period", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            curY += 12;
            gfx2.DrawString("From Date:", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_periodFrom.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("To Date:", fontBold, XBrushes.Black, new XRect(curX + 300, curY, 150, 20), XStringFormat.TopLeft);
            gfx2.DrawString(_periodTo.ToString("dd-MM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 400, curY, 150, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("Basic Premium", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _basicPremium), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);

            if (_NCDPercent == "No NCD(first policy)")
                gfx2.DrawString("(-)NCD(0%):", fontBold, XBrushes.Black, new XRect(curX + 300, curY, 150, 20), XStringFormat.TopLeft);
            else
                gfx2.DrawString("(-)NCD(" + _NCDPercent + "%):", fontBold, XBrushes.Black, new XRect(curX + 300, curY, 150, 20), XStringFormat.TopLeft);

            gfx2.DrawString("SGD " +  String.Format("{0:0,0.00}", _ncdDiscountRate), fontNormal, XBrushes.Black, new XRect(curX + 400, curY, 150, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("OFD(5%):", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _ofdRate), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("NCD Protector", fontBold, XBrushes.Black, new XRect(curX + 300, curY, 150, 20), XStringFormat.TopLeft);
            gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _ncdProtectorRate), fontNormal, XBrushes.Black, new XRect(curX + 400, curY, 150, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("Buy Up/Down Excess", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _buyupdownRate), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);
            //gfx2.DrawString("Add. Discount(5%):", fontBold, XBrushes.Black, new XRect(curX + 300, curY, 150, 20), XStringFormat.TopLeft);
            //gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _addDiscountRate), fontNormal, XBrushes.Black, new XRect(curX + 400, curY, 150, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("Gross Premium", fontBold, XBrushes.Black, new XRect(curX, curY, 150, 20), XStringFormat.TopLeft);
            gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _grossPremium), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 150, 20), XStringFormat.TopLeft);
            gfx2.DrawString("(+) GST(7%):", fontBold, XBrushes.Black, new XRect(curX + 300, curY, 100, 20), XStringFormat.TopLeft);
            gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _gstRate), fontNormal, XBrushes.Black, new XRect(curX + 400, curY, 100, 20), XStringFormat.TopLeft);

            curY += 12;
            gfx2.DrawString("Total Due:", fontBold, XBrushes.Black, new XRect(curX + 300, curY, 150, 20), XStringFormat.TopLeft);
            gfx2.DrawString("SGD " + String.Format("{0:0,0.00}", _totalPremium), fontNormal, XBrushes.Black, new XRect(curX + 400, curY, 150, 20), XStringFormat.TopLeft);

            if (userType == 1)
            {
                curY += 16;
                gfx2.DrawString("Mode of Payment", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("Mode", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
                gfx2.DrawString("Credit Card", fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("Card Type", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
                gfx2.DrawString(_cardType, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("Card Number", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
                gfx2.DrawString(_cardNo, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("Card Expiry Date", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
                gfx2.DrawString(_cardExpiryDate.ToString("MMM-yyyy"), fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);


                curY += 12;
                gfx2.DrawString("Card Holder's Name", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
                gfx2.DrawString(_cardholdersName, fontNormal, XBrushes.Black, new XRect(curX + 120, curY, 100, 20), XStringFormat.TopLeft);

                curY += 20;
                gfx2.DrawString("Declaration", fontBold, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("I DO HEREBY DECLARE AND WARRANT the answers given above are in every respect true and correct and I have not withheld any "
                + "information likely to affect", fontSmall, XBrushes.Black, new XRect(curX, curY, curX + 450, curY + 100), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("acceptance of this Proposal, and agree that this Proposal Declaration shall be the basis of the Contract between the Company and myself, and I further agree to "
                   + "", fontSmall, XBrushes.Black, new XRect(curX, curY, curX + 450, curY + 100), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("accept the Company's Policy subject to the terms, exclusions and conditions to be expressed therein, endorsed thereon or attached thereto.I hereby undertake to "
                + "", fontSmall, XBrushes.Black, new XRect(curX, curY, curX + 450, curY + 100), XStringFormat.TopLeft);

                curY += 12;
                gfx2.DrawString("pay any difference arising from a discrepancy in the NCD declared, failing which the policy shall be cancelled by the Company.", fontSmall, XBrushes.Black, new XRect(curX, curY, curX + 450, curY + 100), XStringFormat.TopLeft);

                curY += 70;
                gfx2.DrawString("Date:", fontNormal, XBrushes.Black, new XRect(curX, curY, 100, 20), XStringFormat.TopLeft);
                gfx2.DrawLine(new XPen(_xcolor), curX + 30, curY + 8, curX + 130, curY + 8);

                gfx2.DrawString("Signature of Proposer and Company Stamp", fontNormal, XBrushes.Black, new XRect(curX + 200, curY, 100, 20), XStringFormat.TopLeft);
                gfx2.DrawLine(new XPen(_xcolor), curX + 380, curY + 8, curX + 500, curY + 8);

                curY += 60;
                gfx2.DrawString("Page 2 of 2", fontSmall, XBrushes.Black, new XRect(curX + 450, curY, 200, 20), XStringFormat.TopLeft);
            }
            else
            {
                curY += 260;
                gfx2.DrawString("Page 2 of 2", fontSmall, XBrushes.Black, new XRect(curX + 450, curY, 200, 20), XStringFormat.TopLeft);
            }

            HttpUtility _server = new HttpUtility();
            string _filePath = GetFilePathBKI();
            string filename = _filePath + strfilename + ".pdf";

        
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            document.Save(filename);
            stream.Close();
            document.Close();

            return filename;
        }

        private string isTrue(string ibool)
        {
            string retval = "Yes";

            if (ibool == "False")
                retval = "No";

            return retval;
        }


        public void ClearFields()
        {
            _proposalNo = "";
            _pageTitle = "Motor Insurance Proposal";

            _revisionNo = "";
            _quotationNo = "";
            _producerCode = "";
            _Applicationdate = DateTime.Now;

            #region Customer Profile
            _customerName = "";
            _customerAddress = "";
            _customerUnitNo = "";
            _customerHomeNo = "";
            _customerPostCode = "";
            _NRIC = "";
            _officemobileNo = "";
            _employersName = "";
            _emailaddress = "";
            _customerGender = "";
            _customerDOB = DateTime.Now;
            _customeroccupation = "";
            _customerjobnature = "";
            _customermaritalstatus = "";
            _customerdrivingexperience = 4;

            #endregion

            #region Addtnal Drivers

            _driver1Name = "John Tn";
            _driver1Gender = "";
            _driver1DOB = DateTime.Now;
            _driver1Occupation = "";
            _driver1JobNature = "";
            _driver1MaritalStatus = "";
            _driver1DrivingExperience = 0;

            _driver2Name = "";
            _driver2Gender = "";
            _driver2DOB = DateTime.Now;
            _driver2Occupation = "";
            _driver2JobNature = "";
            _driver2MaritalStatus = "";
            _driver2DrivingExperience = 0;

            _driver3Name = "";
            _driver3Gender = "";
            _driver3DOB = DateTime.Now;
            _driver3Occupation = "";
            _driver3JobNature = "";
            _driver3MaritalStatus = "";
            _driver3DrivingExperience = 0;

            _driver4Name = "";
            _driver4Gender = "";
            _driver4DOB = DateTime.Now;
            _driver4Occupation = "";
            _driver4JobNature = "";
            _driver4MaritalStatus = "";
            _driver4DrivingExperience = 0;

            _driver5Name = "";
            _driver5Gender = "";
            _driver5DOB = DateTime.Now;
            _driver5Occupation = "";
            _driver5JobNature = "";
            _driver5MaritalStatus = "";
            _driver5DrivingExperience = 0;

            #endregion

            #region Vehicle Details

            _vehicleNo = ""; // "S59D112233";
            _chassisNo = ""; // "S59D112233";
            _bodyType = ""; //"Saloon";
            _engineNo = ""; // "S59D112233";
            _carMake = ""; // "Toyota";
            _carModel = ""; // "Altis";
            _yearOfManufacture = 0; // 2008;
            _yearOfRegistration = 0; // 2008;
            _carCC = 0; // 1498;
            _carSeaters = 0;
            _odometerReading = "";
            _estimatedMarketValue = "";

            #endregion

            #region ClaimDetails

            _currentInsuranceCo = ""; // "AIG";
            _policyNo = "";
            _expiryCancellationDate = DateTime.Now;
            _last3yearsClaimXP = "None";
            _noClaimsLast3Years = "0";
            _NCDPercent = "0";
            _OFD = "Yes";
            _NCDProtector = "No";
            _ncdNilDetails = "Not Applicable";

            _isCarModified = false;
            _modifiedReason = "";

            #endregion

            #region Policy Details

            _financeCo = ""; // "DBS BANK LTD";
            _usage = ""; // "Private Use";
            _typeofcover = ""; // "Comprehensive - Private Car-Preferred Plan";
            _periodFrom = DateTime.Now;
            _periodTo = DateTime.Now;

            #endregion

            #region Other Info

            _driveToWestMalaysia = "Monthly";
            _isConvictedOfMotoringOffense = false;
            _convictedReason = "";

            _isGivenDemeritPoints = false;
            _demeritPointsReason = "";

            _isDisabled = false;
            _disablityReason = "";

            _isRefusedMotorInsurance = false;
            _refusedReason = "";

            _isTerminatedDueToPayment = false;
            _terminatedReason = "";


            #endregion

            #region Payment Details

            _excess = 0;
            _totalPremium = 0;
            _basicPremium = 0;
            _ofdRate = 0;
            _buyupdownRate = 0;
            _gstRate = 0;
            _ncdDiscountRate = 0;
            _ncdProtectorRate = 0;
            _grossPremium = 0;
            _additionalDriverCharge = 0;
            
            
            _cardType = ""; // "Master";
            _cardNo = ""; // "1111 2222 3333 XXXX";
            _cardExpiryDate = DateTime.Now;
            _cardholdersName = ""; // "JAMES TESTER";

            #endregion

        }

        public string GetFilePathBKI()
        {
            string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.FileOutputPath").ToString();
            _filePath += "pdfoutput\\BKI\\";
            CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();
            string _todaydate = DateTime.Now.ToString("yyyyMMMdd");
            if (!_myIO.CheckDirectory(_filePath + _todaydate))
            {
                if (_myIO.CreateDirectory(_filePath, _todaydate))
                {
                    _filePath += _todaydate + "\\";
                }
            }
            else
            {
                _filePath += _todaydate + "\\";
            }

            return _filePath;
        }

    }
}
